﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.InboundDetailServiceRef;

    public class InboundDetailServiceClientProxy : BasePage
    {
        public string AutoPutAway(string receiptID, List<string> receiptLineID, string updatedBy)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.AutoPutAway(receiptID, receiptLineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string BatchReceiving(string receiptID, List<string> receiptLineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.BatchReceiving(receiptID, receiptLineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string CheckSkuIDExist(string orderID, string skuID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.CheckSkuIDExist(orderID, skuID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ConfirmPutAway(List<PutawayDetailInfo> putawayDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.ConfirmPutAway(putawayDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteReceiptDetailInfo(List<string> receiptID, List<string> receiptLineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.DeleteReceiptDetailInfo(receiptID, receiptLineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ExecuteReceiving(ReceiptDetailInfo receiptDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.ExecuteReceiving(receiptDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ExecuteReceivingAll(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.ExecuteReceivingAll(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string GenPutAway(List<ReceiptPutawayInfo> receiptPutawayInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.GenPutAway(receiptPutawayInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public static InboundDetailServiceClientProxy GetInstance()
        {
            return new InboundDetailServiceClientProxy();
        }

        public ReceiptDetailInfo GetNextUncompletedReceiptDetailInfo(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptDetailInfo receiptDetailInfo = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                receiptDetailInfo = client.GetNextUncompletedReceiptDetailInfo(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptDetailInfo;
        }

        public List<ReceiptPutawayInfo> GetPendingPutAwayTaskByTransID(string transID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            List<ReceiptPutawayInfo> receiptPutawayInfoList = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                receiptPutawayInfoList = client.GetPendingPutAwayTaskByTransID(transID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptPutawayInfoList;
        }

        public DataSet GetPutAwayDetailByPagerQueryEntity(PutawayDetailQueryEntity putawayDetailQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                ds = client.GetPutAwayDetailByPagerQueryEntity(putawayDetailQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public ReceiptDetailInfo GetReceiptDetailInfoByID(string receiptID, string receiptLineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            ReceiptDetailInfo receiptDetailInfo = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                receiptDetailInfo = client.GetReceiptDetailInfoByID(receiptID, receiptLineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return receiptDetailInfo;
        }

        public DataSet GetReceiptDetailInfoByPagerQueryEntity(ReceiptDetailQueryEntity receiptDetailQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                ds = client.GetReceiptDetailInfoByPagerQueryEntity(receiptDetailQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetReceiptDetailInfoByQueryEntity(ReceiptDetailQueryEntity receiptDetailQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                ds = client.GetReceiptDetailInfoByQueryEntity(receiptDetailQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetReceiptHistoryByPagerQueryEntity(ReceiptHistoryQueryEntity receiptHistoryQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                ds = client.GetReceiptHistoryByPagerQueryEntity(receiptHistoryQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public ReceiptDetailQueryEntity GetReceiptInfoByQueryEntity(ReceiptDetailQueryEntity receiptDetailQuery)
        {
            return null;
        }

        public DataSet GetReceiptInquiryInfoByQueryEntity(ReceiptDetailQueryEntity receiptDetailQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                ds = client.GetReceiptInquiryInfoByQueryEntity(receiptDetailQuery, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public List<string> GetUnPrintPutawayTaskIDByReceiptID(string receiptID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            List<string> stringList = null;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                stringList = client.GetUnPrintPutawayTaskIDByReceiptID(receiptID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return stringList;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertReceiptDetailInfo(ReceiptDetailInfo receiptDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.InsertReceiptDetailInfo(receiptDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string ReceiptDetailPriceChanges(string receiptID, string lineID, string IsPalletized, float price, float Totalprice)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.ReceiptDetailPriceChanges(receiptID, lineID, IsPalletized, price, Totalprice, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateReceiptDetailInfo(ReceiptDetailInfo receiptDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            InboundDetailServiceClient client = new InboundDetailServiceClient("WSHttpBinding_IInboundDetailService");
            try
            {
                result = client.UpdateReceiptDetailInfo(receiptDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

